package com.tds.wechathelper.filter.impl;

import java.util.ArrayList;
import java.util.List;

import com.tds.wechathelper.filter.AbstractFilterChain;
import com.tds.wechathelper.filter.Filter;

public class DefaultFilterChain extends AbstractFilterChain implements Filter{

	private List<Filter> filters = new ArrayList<Filter>(2);
	private Filter dispacherFilter = DISPACHER_FILTER;
	private int cursor = -1;

	@Override
	public void addFilter(Filter filter) {
		filters.add(filter);
	}

	@Override
	public Filter nextFilter() {
		Filter filter = null;
		if(cursor == -1){
			filter = dispacherFilter;
			cursor++;
		}else if(cursor < filters.size()){
			filter = filters.get(cursor++);
		}else{
			filter = NULL_FILTER;
		}
		return filter;
	}
	
}
